fix(archive): skip checkpoint when worktree was deleted externally#1910
Merged
jonathanlab merged 1 commit intomainfrom Apr 29, 2026
Conversation
This was referenced Apr 28, 2026
Contributor
Author
This was referenced Apr 28, 2026
Contributor
Prompt To Fix All With AIThis is a comment left during a code review.
Path: apps/code/src/main/services/archive/service.ts
Line: 187-218
Comment:
**Prefer `if/else` over two separate `if` blocks**
The two independent `if (!worktreeIsValid)` / `if (worktreeIsValid)` blocks are mutually exclusive and can be collapsed into a single `if/else`, removing the superfluous second condition check and making the intent clearer.
```suggestion
if (worktreeIsValid) {
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(archive): skip checkpoint when workt..." | Re-trigger Greptile |
Comment on lines
+187
to
+218
| if (!worktreeIsValid) { | ||
| log.warn( | ||
| `Worktree at ${worktreePath} is missing or not a git repository; skipping checkpoint capture`, | ||
| ); | ||
| archivedTask.checkpointId = null; | ||
| } | ||
|
|
||
| if (worktreeIsValid) { | ||
| const actualBranch = await this.getCurrentBranchName(worktreePath); | ||
| if (actualBranch && actualBranch !== "HEAD") { | ||
| archivedTask.branchName = actualBranch; | ||
| } | ||
|
|
||
| await step( | ||
| async () => { | ||
| if (!archivedTask.checkpointId) { | ||
| throw new Error("checkpointId must be set for worktree mode"); | ||
| } | ||
| await this.captureWorktreeCheckpoint( | ||
| folderPath, | ||
| worktreePath, | ||
| archivedTask.checkpointId, | ||
| ); | ||
| }, | ||
| async () => { | ||
| if (archivedTask.checkpointId) { | ||
| const git = createGitClient(folderPath); | ||
| await deleteCheckpoint(git, archivedTask.checkpointId); | ||
| } | ||
| }, | ||
| ); | ||
| } |
Contributor
There was a problem hiding this comment.
Prefer
if/else over two separate if blocks
The two independent if (!worktreeIsValid) / if (worktreeIsValid) blocks are mutually exclusive and can be collapsed into a single if/else, removing the superfluous second condition check and making the intent clearer.
Suggested change
| if (!worktreeIsValid) { | |
| log.warn( | |
| `Worktree at ${worktreePath} is missing or not a git repository; skipping checkpoint capture`, | |
| ); | |
| archivedTask.checkpointId = null; | |
| } | |
| if (worktreeIsValid) { | |
| const actualBranch = await this.getCurrentBranchName(worktreePath); | |
| if (actualBranch && actualBranch !== "HEAD") { | |
| archivedTask.branchName = actualBranch; | |
| } | |
| await step( | |
| async () => { | |
| if (!archivedTask.checkpointId) { | |
| throw new Error("checkpointId must be set for worktree mode"); | |
| } | |
| await this.captureWorktreeCheckpoint( | |
| folderPath, | |
| worktreePath, | |
| archivedTask.checkpointId, | |
| ); | |
| }, | |
| async () => { | |
| if (archivedTask.checkpointId) { | |
| const git = createGitClient(folderPath); | |
| await deleteCheckpoint(git, archivedTask.checkpointId); | |
| } | |
| }, | |
| ); | |
| } | |
| if (worktreeIsValid) { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/main/services/archive/service.ts
Line: 187-218
Comment:
**Prefer `if/else` over two separate `if` blocks**
The two independent `if (!worktreeIsValid)` / `if (worktreeIsValid)` blocks are mutually exclusive and can be collapsed into a single `if/else`, removing the superfluous second condition check and making the intent clearer.
```suggestion
if (worktreeIsValid) {
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
adboio
approved these changes
Apr 28, 2026
Comment on lines
+187
to
+218
| if (!worktreeIsValid) { | ||
| log.warn( | ||
| `Worktree at ${worktreePath} is missing or not a git repository; skipping checkpoint capture`, | ||
| ); | ||
| archivedTask.checkpointId = null; | ||
| } | ||
|
|
||
| if (worktreeIsValid) { | ||
| const actualBranch = await this.getCurrentBranchName(worktreePath); | ||
| if (actualBranch && actualBranch !== "HEAD") { | ||
| archivedTask.branchName = actualBranch; | ||
| } | ||
|
|
||
| await step( | ||
| async () => { | ||
| if (!archivedTask.checkpointId) { | ||
| throw new Error("checkpointId must be set for worktree mode"); | ||
| } | ||
| await this.captureWorktreeCheckpoint( | ||
| folderPath, | ||
| worktreePath, | ||
| archivedTask.checkpointId, | ||
| ); | ||
| }, | ||
| async () => { | ||
| if (archivedTask.checkpointId) { | ||
| const git = createGitClient(folderPath); | ||
| await deleteCheckpoint(git, archivedTask.checkpointId); | ||
| } | ||
| }, | ||
| ); | ||
| } |
a5618da to
45304f5
Compare
c67bb56 to
271ba9c
Compare
Contributor
Author
Merge activity
|
271ba9c to
1640b9e
Compare
45304f5 to
7989298
Compare
When a workspace's worktree directory was deleted by an external process, archiving failed because CaptureCheckpointSaga ran against a non-git path and threw "fatal: not a git repository". The rollback then restored the task, producing the flash-and-reappear behavior reported in #1798. Now we probe the worktree with isGitRepository before checkpointing; if the path is missing or invalid, we log the reason, set checkpointId to null, and continue with the remaining cleanup steps. A null checkpointId naturally causes unarchive to skip worktree restoration. Generated-By: PostHog Code Task-Id: eeaa1905-3fe5-423c-a853-08d75e78947b
7989298 to
e5704e9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #1798